<input id="clitty-click" type="checkbox"/>
<div id="console"/>
<script src="../../resources/js-test.js"></script>
<script>
description("This tests that isTrusted returns the correct value under certain situations.")

var redispatched = false;

function createAndInitEvent() {
    var e = document.createEvent('Event');
    e.initEvent(false, false, false);
    return e;
}

shouldBeFalse("document.createEvent('Event').isTrusted");
shouldBeFalse("createAndInitEvent().isTrusted");

function originalDispatch(e) {
    originalEvent = e;
}

function redispatch(e) {
    redispatched = true;   
}

var element = document.getElementById("clitty-click");
if (window.eventSender) {
    element.addEventListener('click', originalDispatch);
    element.addEventListener('focus', function (e) {
        event = e;
        shouldBeTrue("event.isTrusted");
    });
    eventSender.mouseMoveTo(element.offsetLeft, element.offsetTop);
    eventSender.mouseDown();
    eventSender.mouseUp();

    shouldBeTrue("originalEvent.isTrusted");
    element.removeEventListener('click', originalDispatch);
    element.addEventListener('click', redispatch);

    element.dispatchEvent(originalEvent);
    shouldBeTrue("redispatched");
    shouldBeFalse("originalEvent.isTrusted");

    originalEvent = null;
    element.removeEventListener('click', redispatch);
    element.addEventListener('click', originalDispatch);
    element.click();
    shouldBeFalse("originalEvent.isTrusted");
}

</script>
